//package com.authine.cloudpivot.web.api.advice;
//
//import com.alibaba.fastjson.JSONObject;
//import com.authine.cloudpivot.engine.api.facade.BizObjectFacade;
//import com.authine.cloudpivot.engine.api.model.runtime.BizObjectModel;
//import com.authine.cloudpivot.engine.api.model.runtime.BizObjectQueryModel;
//import com.authine.cloudpivot.engine.component.query.api.FilterExpression;
//import com.authine.cloudpivot.engine.component.query.api.Page;
//import com.authine.cloudpivot.engine.component.query.api.helper.PageableImpl;
//import com.authine.cloudpivot.engine.component.query.api.helper.Q;
//import com.authine.cloudpivot.ext.controller.PocZcController;
//import com.authine.cloudpivot.web.api.util.AuthUtils;
//import com.authine.cloudpivot.web.api.view.PageVO;
//import com.authine.cloudpivot.web.api.view.ResponseResult;
//import com.authine.cloudpivot.web.api.view.runtime.FormDataVO;
//import com.authine.cloudpivot.web.api.view.runtime.QueryDataVO;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Before;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Objects;
//import java.util.stream.Collectors;
//
///**
// * @Author hxd
// * @Date 2021/12/17 14:23
// * @Description
// **/
//@Slf4j
//@Aspect
//@Component
//public class SheetLoadAspect {
//
//
//    @Autowired
//    PocZcController pocZcController;
//    @Autowired
//    BizObjectFacade bizObjectFacade;
//
//    /**
//     * Pointcut 切入点
//     *
//     */
//    @Pointcut("execution(* com.authine.cloudpivot.web.api.controller.runtime.FormRuntimeController.load(..))")
//    public void loadAspect(){}
//    /**
//     * 环绕通知
//     */
//    @Around(value = "loadAspect()")
//    public Object arround(ProceedingJoinPoint pjp) throws Throwable {
//
//        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = attributes.getRequest();
//
//        String schemaCode=request.getParameter("schemaCode");
//        String sheetCode=request.getParameter("sheetCode");
//
//        Object proceed = pjp.proceed();
//
//        if ("kcqd".equals(schemaCode) && "courseCenterDetail".equals(sheetCode) ){
//            log.info("\n=============进入 课程中心详情数据处理");
//
//            // 处理完请求，返回内容
//            ResponseResult<FormDataVO> result = (ResponseResult<FormDataVO>)proceed;
//
//            if (0l==result.getErrcode()){
//                String bizId = result.getData().getBizObject().getId();
//
//                BizObjectQueryModel queryModel = new BizObjectQueryModel();
//                queryModel.setSchemaCode("liked");
//                queryModel.setQueryCode("liked");
//                queryModel.setPageable(new PageableImpl(0,1));
//                List<FilterExpression> itList = new ArrayList<>();
//                FilterExpression.Item it = Q.it("courseId", FilterExpression.Op.Eq, bizId);
//                itList.add(it);
//
//
//                it = Q.it("creater", FilterExpression.Op.Eq,  AuthUtils.getUserId());
//                itList.add(it);
//                FilterExpression.And and = Q.and(itList);
//
//                queryModel.setFilterExpr(and);
//                Page<BizObjectModel> page = bizObjectFacade.queryBizObjects(queryModel);
//
//                if (page.getTotal()>0){
//                    result.getData().getBizObject().put("sfydz",true);
//                }
//            }
//        }
//
//        return proceed;
//    }
//
//    /**
//     * 方法执行前
//     */
//    @Before(value = "loadAspect()")
//    public void before(JoinPoint joinPoint){
////        log.info("2、Before：方法执行开始...");
////        // 接收到请求，记录请求内容
//        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
////        assert attributes != null;
//        HttpServletRequest request = attributes.getRequest();
////        // 记录下请求内容
////        log.info("URL : " + request.getRequestURL().toString());
////        log.info("HTTP_METHOD : " + request.getMethod());
////        log.info("IP : " + request.getRemoteAddr());
////        log.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
////        log.info("=======================ARGS : " + Arrays.toString(joinPoint.getArgs()));
//
//        try {
//
//            String schemaCode = request.getParameter("schemaCode");
//            String objectId = request.getParameter("objectId");
//
//            if ("kcqd".equals(schemaCode) && Objects.nonNull(objectId)){
//                log.info("\n=============点击量增加");
//
//                //点击量增加
//                pocZcController.courseStatistics(objectId,1);
//
//            }
//
//
//        } catch (Exception e) {
//            log.info("list 日志添加失败:{}", e);
//        }
//
//    }
//
//
//    private JSONObject getParam(Object[] args){
//        if (args != null) {
//            return (JSONObject) JSONObject.toJSON(args[0]);
//        }
//
//        return null;
//    }
//
//    /**
//     * 方法执行结束，不管是抛出异常或者正常退出都会执行
//     */
////    @After(value = "listAspect()")
//    public void after(JoinPoint joinPoint){
//
//
//    }
//
//    /**
//     * 方法执行结束，增强处理
//     */
////    @AfterReturning(returning = "ret", pointcut = "webLog()")
//    public void doAfterReturning(Object ret){
//        // 处理完请求，返回内容
//
//    }
//
//    /**
//     * 后置异常通知
//     */
////    @AfterThrowing(value = "webLog()")
//    public void throwss(JoinPoint joinPoint){
//
//    }
//}
